from selenium.webdriver import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

from utils_tools import DriverTools


class BasePage:

    def __init__(self):
        self.driver = DriverTools.open_driver()

    def get_url(self, url):
        self.driver.get(url)

    def get_element(self, by, element):
        return WebDriverWait(self.driver, 10, 1).until(lambda x: x.find_element(by, element))

    def get_elements(self, by, element):
        return WebDriverWait(self.driver, 10, 1).until(lambda x: x.find_elements(by, element))

    def element_click(self, by, element):
        self.get_element(by, element).click()

    def element_send_keys(self, by, element, keys):
        self.get_element(by, element).send_keys(keys)

    def get_element_text(self, by, element):
        return self.get_element(by, element).text

    def get_element_texts(self, by, element):
        text = self.get_elements(by, element).text
        listText = []
        for x in text:
            listText.append(x.text)
        return listText

    def element_iframe(self, by, element):
        self.driver.switch_to.frame(self.get_element(by, element))

    def element_default_content(self):
        self.driver.switch_to.default_content()

    def element_down_index(self, by, element, index):
        Select(self.get_element(by, element)).select_by_index(index)

    def element_move_to(self, by, element):
        ActionChains(self.driver).move_to_element(self.get_element(by, element)).perform()




